const app = getApp();
const util = require('../../utils/util.js');
Page({
    data: {
        borrow_status: 1, // borrow_status 1 为租借成功 0 为租借失败
        info: {},
    },
    onLoad(options) {
        my.showLoading({
            content: 'loading...'
        });
        let used_id = options.used_id;
        let borrow_status = options.borrow_status;
        this.setData({
            borrow_status: borrow_status
        });
        // 获取使用记录信息
        if (borrow_status == 1) {
            // 租借成功
            this.getUsed(used_id);
        } else if (borrow_status == 0) {
            this.unfreeze(used_id);
        }
        my.hideLoading();
    },
    // ===============  获取使用记录信息 ==========================
    getUsed(used_id) {
        let that = this;
        util.httpRequest('/getUsed', {
            used_id: used_id
        }, function (res) {
            if (res.code == 1) {
                that.setData({
                    info: res.data
                })
            }
        })
    },
    // ==================== 跳转到个人用户页面 ==============================
    goToUser() {
        //跳转用户界面
        my.reLaunch({
            url: '../user/user'
        });
    },
    // ==================  跳转到首页index ===========================
    goToIndex() {
        my.reLaunch({
            url: '../index/index'
        });
    },
    // ===================  借出失败解冻订单 =============================
    unfreeze(used_id) {
        let that = this;
        my.showLoading({
            content: 'loading...'
        });
        util.httpRequest('/doUnfreeze', {
            used_id: used_id
        }, function (res) {
            my.hideLoading();
            if (res.code == 1) {
                my.showToast({
                    content: res.msg,
                    type: 'none',
                    duration: 3000
                });
            }
        })
    },

});
